import {
  BasePageDto,
  BaseTencentCaptchaDto,
  BaseVcodeDto,
} from '@/common/base/base.dto';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import {
  IsEnum,
  IsInt,
  IsNotEmpty, IsNumberString,
  IsOptional,
  IsString, Matches,
  Max, MaxLength,
  Min,
} from 'class-validator';
import { UserTitleCertification } from "common/utils/data";
import { MOBILE_REGEXP, PASSWORD_REGEXP, USERNAME_REGEXP } from "common/utils/regexp";

export class UserVerifyRegisterDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @Matches(MOBILE_REGEXP)
  mobile?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @Matches(USERNAME_REGEXP)
  name?: string;
}

export class UserCreateDto extends BaseVcodeDto {
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @Matches(MOBILE_REGEXP)
  mobile: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @Matches(USERNAME_REGEXP)
  name: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @Matches(PASSWORD_REGEXP)
  password: string;
}

export class UserUpdatePasswordDto extends BaseVcodeDto{
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @Matches(PASSWORD_REGEXP)
  password: string;
}

export class UserResetPasswordDto extends BaseVcodeDto{
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @Matches(MOBILE_REGEXP)
  mobile: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  @Matches(PASSWORD_REGEXP)
  password: string;
}

export class UserUpdateDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  avatar?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @MaxLength(20)
  title?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  @MaxLength(50)
  signature?: string;
}

export class UserLoginDto{
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  mobile: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  password?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  vcodeKey?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  vcode?: string;
}

export class UserMobileLoginWxDto {
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  nameOrMobile: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  password: string;

  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  jsCode: string;
}

export class UserMobilePreLoginWxDto {
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  jsCode: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  token?: string;
}

export class UserAdminIndexDto extends BasePageDto {
  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  name?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  mobile?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  createTimeStart?: string;

  @IsOptional()
  @ApiPropertyOptional()
  @IsString()
  createTimeEnd?: string;
}

export class UserAdminUpdateDto {
  @IsOptional()
  @ApiPropertyOptional({
    description: '状态',
  })
  @IsInt()
  @Max(1)
  @Min(0)
  status?: number;

  @IsOptional()
  @ApiPropertyOptional({
    description: '头衔认证',
  })
  @IsEnum(UserTitleCertification)
  titleCertification?: UserTitleCertification;
}

export class UserOpenApiLoginCheckDto{
  @IsNotEmpty()
  @ApiProperty()
  @IsString()
  token: string;
}
